home *** CD-ROM | disk | FTP | other *** search
/ PC Shareware 1997 February / PC Shareware 1997-02.iso / programy / e! / api / mulhelp2.pa_ / mulhelp2.PAS
Encoding:
Pascal/Delphi Source File  |  1995-03-05  |  7.4 KB  |  256 lines

  1. {************************************************}
  2. {                         }
  3. { E! for Windows                 }
  4. { (c) - Patrick Philippot - 1992,1993         }
  5. {                         }
  6. { MulHelp2 Extension DLL - version 2.1         }
  7. {                         }
  8. { Supporting multiple Help Files from E!.     }
  9. {                         }
  10. {************************************************}
  11.  
  12. (*
  13. MULHELP2 is a much more sophisticated version of MULHELP. There are
  14. many situations where you have to refer to multiple help files. For
  15. example, when writing Visual C++ source code with E!, you may want
  16. to refer to the Windows 3.1 SDK, the MFC 2.5 and the C/C++ language
  17. help files. It would be nice to load one of this file at will when
  18. the cursor is located on a keyword.
  19.  
  20. With MULHELP2 you can.
  21.  
  22. With MULHELP, each alternate help file was assigned a different key.
  23. MULHELP2 has another approach. When you hit SHIFT+F1 (or the key that
  24. you have assigned to the AlternateHelp function), a listbox is
  25. displayed, showing the list of all the alternate help files that you
  26. have specified in EW.INI. Select one of these and WinHelp will be
  27. called with the selected help file and the current keyword as
  28. parameters.
  29.  
  30. But there's more to MULHELP2, however. This DLL installs a hook on the
  31. JumpToDefinition function. When you ask E! to jump to a function definition
  32. and when E! can't find this definition in the TAG file, MULHELP2 takes
  33. control and asks the user whether he wants the keyword to be passed to
  34. one of the registered help files.
  35.  
  36.  
  37. Installing MULHELP2
  38. *******************
  39.  
  40. The first thing you have to do is to create a new section in EW.INI:
  41. [extended help]. Then, you will list in that section the help files
  42. you want to use, as follows (this is an example):
  43.  
  44. HelpName1=win31wh.hlp
  45. HelpName2=mfc.hlp
  46. HelpName3=mscxx.hlp
  47.  
  48. You must then add a description for each of these files:
  49.  
  50. HelpDesc1=Windows SDK Help File
  51. HelpDesc2=MFC 2.5 Help File
  52. HelpDesc3=Microsoft C/C++ Language Help File
  53.  
  54. and so on...
  55.  
  56. You should then load MULHELP2 from the User menu (you can also
  57. install MULHELP2 as an autoloaded EWD). MULHELP2.EWD must reside in
  58. your USER directory.
  59.  
  60. WARNING!!
  61.  
  62. If you had previously installed MULHELP.EWD, you should unload it,
  63. remove it from your autoload list if necessary and remove any
  64. assignment to the SHIFT+F1 key (or to the key to which you have
  65. assigned the AlternateHelp function).
  66.  
  67. Once MULHELP2 is loaded, when you hit SHIFT+F1, the list of help
  68. file descriptors will be displayed and you'll just have to select
  69. one to get help about the current keyword if it is relevant for the
  70. selected help file.
  71.  
  72.  
  73. Enjoy!
  74.  
  75. Patrick Philippot
  76. 04/22/94
  77. *)
  78.  
  79. {$I compdir.inc}
  80. {$C MOVEABLE PRELOAD DISCARDABLE}
  81. {$R mulhelp2.res}
  82.  
  83. library MulHelp;
  84.  
  85. uses WinProcs, WinTypes, EWApImp2, Strings;
  86.  
  87. {$I ewuser.inc}
  88.  
  89. const
  90.   HelpEntry   : PChar = 'HelpName';
  91.   HelpDesc    : PChar = 'HelpDesc';
  92.   HelpSection : PChar = 'Extended Help';
  93.   Profile     : PChar = 'ew.ini';
  94.  
  95.   id_Listbox  = 100;
  96.  
  97. var
  98.   EntryValue    : array[0..80] of char;
  99.   HelpCurEntry    : array[0..80] of char;
  100.   SaveExit    : Pointer;
  101.   ListBoxHandle : THandle;
  102.   OkBtHandle    : THandle;
  103.   ChoiceProc    : TFarProc;
  104.  
  105.  
  106. function ChoiceDlg(Dialog: HWnd; Message, WParam: Word; LParam: Longint): Bool; export;
  107. {-This is the dialog procedure managing the Help File Description List}
  108.  
  109. var
  110.   Index    : integer;
  111.   IndexStr : array[0..3] of char;
  112.  
  113. label
  114.   OKSelect;
  115.  
  116. begin
  117.   ChoiceDlg := True;
  118.   case Message of
  119.     wm_InitDialog:
  120.       begin
  121.        {-Get handle of Listbox}
  122.     ListBoxHandle := GetDlgItem(Dialog, id_ListBox);
  123.     OkBtHandle := GetDlgItem(Dialog, id_Ok);
  124.     EnableWindow(OkBtHandle, false);
  125.     SetFocus(ListBoxHandle);
  126.        {-Fill listbox with name of registered help files}
  127.     Index := 1;
  128.     Str(Index, IndexStr);
  129.     StrCat(StrCopy(HelpCurEntry, HelpDesc), IndexStr);
  130.        {-Iterate through list of help file descriptors}
  131.     while GetPrivateProfileString(HelpSection,
  132.                       HelpCurEntry,
  133.                       '',
  134.                       EntryValue,
  135.                       SizeOf(EntryValue),
  136.                       Profile) <> 0 do begin
  137.      {-Add descriptor to Listbox}
  138.       SendMessage(ListBoxHandle, lb_AddString, 0, longint(Addr(EntryValue)));
  139.       Inc(Index);
  140.       Str(Index, IndexStr);
  141.       StrCat(StrCopy(HelpCurEntry, HelpDesc), IndexStr);
  142.     end;
  143.       end;
  144.     wm_Command:
  145.       begin
  146.     case WParam of
  147.       id_Listbox:
  148.         if HiWord(LParam) = lbn_DblClk then
  149.           Goto OKSelect
  150.         else if HiWord(LParam) = lbn_SelChange then
  151.           EnableWindow(OkBtHandle, true);
  152.       id_Ok:
  153.         begin
  154. OkSelect:
  155.           Index := SendMessage(ListBoxHandle, lb_GetCurSel, 0, 0);
  156.           if Index <> lb_Err then begin
  157.          {-A Help File Descriptor is currently selected}
  158.         Str(Index + 1, IndexStr);
  159.         StrCat(StrCopy(HelpCurEntry, HelpEntry), IndexStr);
  160.            {-Get the corresponding help filename}
  161.         if GetPrivateProfileString(HelpSection,
  162.                        HelpCurEntry,
  163.                        '',
  164.                        EntryValue,
  165.                        SizeOf(EntryValue),
  166.                        Profile) <> 0 then begin
  167.          {-It is important to close the dialog box before calling an E! API
  168.            function. Otherwise, E! is unable to know which Edit Window is active}
  169.           EndDialog(Dialog, id_Ok);
  170.           WritePrivateProfileString('system',
  171.                         'alternatehelp',
  172.                         EntryValue,
  173.                         Profile);
  174.           EWAlternateHelp(EWGetCaretPosX, EWGetCaretPosY);
  175.           Exit;
  176.         end else begin
  177.            {-No Help Filename could be found for the Descriptor with this index}
  178.           MessageBeep(0);
  179.           EWMessageBox(GetFocus,
  180.                    'Can''t find related Help File.',
  181.                    'Error!',
  182.                    mb_Ok or mb_IconExclamation);
  183.         end;
  184.           end else begin
  185.         MessageBeep(0);
  186.         EWMessageBox(GetFocus,
  187.                  'No Help File Selected.',
  188.                  'Error!',
  189.                  mb_Ok or mb_IconExclamation);
  190.           end;
  191.         end;
  192.       id_Cancel:
  193.         begin
  194.           EndDialog(Dialog, id_Cancel);
  195.           Exit;
  196.         end;
  197.     end;
  198.       end;
  199.   end;
  200.   ChoiceDlg := False;
  201. end;
  202.  
  203. function FuncEntryHook(command : word) : integer; export;
  204. {-Install a hook for the AlternateHelp function.          }
  205.  
  206. const
  207.   bInUse : boolean  = false;
  208.  
  209. begin
  210.   if not bInUse and (command = ew_AlternateHelp) then begin
  211.     FuncEntryHook := 1;
  212.     bInUse := true;
  213.     ChoiceProc := MakeProcInstance(@ChoiceDlg, HInstance);
  214.     DialogBox(HInstance, 'HelpList', GetFocus, ChoiceProc);
  215.     FreeProcInstance(ChoiceProc);
  216.     bInUse := false;
  217.   end else
  218.     FuncEntryHook := 0;
  219. end;
  220.  
  221. function FuncExitHook(command : word; pRetCode : PInteger) : integer; export;
  222. {-Check whether the JumpToDef function succeeded.}
  223. { If not, ask the user whether the keyword should passed to a help file}
  224.  
  225. begin
  226.   FuncExitHook := 0;
  227.  {-Although the current version of the EW API doesn't check the return code}
  228.  { from the FuncExitHook functions, it is good practice to set this value  }
  229.  { to 0.}
  230.   if (command = ew_MCJumpToDef) and (pRetcode^ <> 0) then
  231.     if EwMessageBox(GetFocus,
  232.              'No Definition found for this function. Pass Keyword to a Help File?',
  233.              'Error',
  234.             mb_YesNo) = id_Yes then
  235.     pRetcode^ := EWAlternateHelp(EWGetCaretPosX, EWGetCaretPosY);
  236. end;
  237.  
  238. procedure LibExit; far;
  239. begin
  240. {-Uninstall Hook before exiting}
  241.   EWRemoveHook(EWHook_FunctionEntry, @FuncEntryHook);
  242.   EWRemoveHook(EWHook_FunctionExit, @FuncExitHook);
  243.   ExitProc := SaveExit;
  244. end;
  245.  
  246. exports
  247.   FuncEntryHook   index 1;
  248.  
  249. begin
  250. {-Install Function Entry Hook on the AlternateHelp function}
  251.   EWSetHook(EWHook_FunctionEntry, @FuncEntryHook);
  252.   EWSetHook(EWHook_FunctionExit, @FuncExitHook);
  253.   SaveExit := ExitProc;
  254.   ExitProc := @LibExit;
  255. end.
  256.